package com.test.demo.controller;

import com.test.demo.po.Email;
import com.test.demo.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MainController {
    @Autowired
    MailService mailService;

    final String myEmail = "1943133326@qq.com";
    final String toEmail = "2133048524@qq.com";

    @PostMapping("/sendEmail")
    public Map<String,String> sendEmailPostFunctions(@RequestBody Email m) {
        Map<String, String> map = new HashMap<>();
        try {
            mailService.sendSimpleMail(myEmail,
                    toEmail,
                    toEmail,
                    m.getTitle(),
                    m.getContent());
        }catch (Exception e) {
            map.put("msg","邮件发送失败！");
            return map;
        }
        map.put("msg","邮件发送成功! 感谢您的来信！");
        return map;
    }

    @GetMapping("/sendEmail")
    public Map<String,String> sendEmailGetFunctions(@RequestParam String title, @RequestParam String content) {
        Map<String, String> map = new HashMap<>();
        try {
            mailService.sendSimpleMail(myEmail,
                    toEmail,
                    toEmail,
                    title,
                    content);
        }catch (Exception e) {
            map.put("msg","邮件发送失败！");
            return map;
        }
        map.put("msg","邮件发送成功! ");
        return map;
    }




}
